package com.itheima.controller;

import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


@RestController
@Api(tags = "检查项管理开发")  // 作用在类上
public class CheckItemController {

    @Reference
    private CheckItemService checkItemService;

    @GetMapping("checkitem/findAll")
    @PreAuthorize("hasAuthority('CHECKITEM_FINDALL')")
    public Result findAll() {
        return new Result(checkItemService.list());
    }


    @PostMapping("checkitem/findPage")
    @ApiOperation(value = "分页查询", notes = "根据客户端请求，完成分页查询")//   添加业务方法上
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "分页页码", required = true, paramType = "form", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示记录个数", required = true, paramType = "form", dataType = "Integer"),
            @ApiImplicitParam(name = "queryString", value = "查询条件", required = false, paramType = "form", dataType = "String")
    })
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        return new Result(checkItemService.findPage(queryPageBean)); //   total  +  List
    }

    //完成检查项管理的添加功能
    //进行全局异常处理
    @PostMapping("checkitem/saveOrUpdate")
    //根据传入的数据是否有id来判断调用哪个方法
    public Result saveOrUpdate(@RequestBody CheckItem checkItem) {
        return new Result(checkItemService.saveOrUpdate(checkItem));
    }

    @DeleteMapping("checkitem/deleteCheckitemById/{id}")
    public Result deleteCheckitemById(@PathVariable("id") Integer id) {
        return new Result(checkItemService.deleteCheckitemById(id));
    }


}








